import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import whoami from '../../atom/whoami';
import p001 from './p001';


export default async function a002(fd: IFeidaoAiBrowserComponent) {
	// todo

	const res = await whoami(fd);
	const a = res.params as { productid: string, staff_no: string };
	const staff_no = a.staff_no;
	// const staff_no = 'YG000029';
	const productid = res.params.productid;
	set(fd, 'productid', productid);
	set(fd, 'staff_no', staff_no);

	const query = {
		productid,
		staff_no
	};


	/**
	 * 拿到总条数
	 */
	const total_count = await nodejs<{ size: number }>('common/zjc-000005/s002', query);
	console.log(total_count);
	const size = total_count.size;
	console.log('sizesizesize:' + size);

	const data = await nodejs<{ array1: Array<{}>, array2: Array<{}>, array3: Array<{}> }>('common/zjc-000005/s001', query);
	console.log('datadatadata:');
	console.log(data);
	if (data.array2.length > 0) {
		render(fd, data.array1, p001, 'p001', 'inner');
	} else {
		render(fd, data.array3, p001, 'p001', 'inner');
	}

}
